<template>
  <div class="setparameter">
    <!-- <el-button @click="handleClick"></el-button> -->
    <el-dialog
      width="700px"
      custom-class="customWidth"
      center
      :before-close="closeDialog"
      title="单位参数配置"
      :close-on-click-modal="false"
      :visible.sync="addDialogFormVisible"
    >
      <div class="unit_parameter">
        <!-- <div class="header_title">
        <span>移动端功能参数</span>
        </div>-->
        <div class="list">
          <el-form
            ref="alldata"
            :model="alldata"
            :rules="alldatarule"
            :label-position="labelPosition"
            label-width="220px"
          >
            <el-form-item label="钱包模式设置:">
              <el-col :span="12">
                <el-select
                  v-model="alldata.walletModel"
                  placeholder="请选择"
                  style="width:100%"
                  size="mini"
                >
                  <el-option
                    v-for="item in walletModelList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item label="挂失卡后是否可以立即补卡:">
              <el-col :span="6">
                <!-- 0 是 1 否 -->
                <el-switch
                  v-model="alldata.replaceModel"
                  active-text="是"
                  inactive-text="否"
                  :active-value="0"
                  :inactive-value="1"
                ></el-switch>
              </el-col>
              <el-col :span="6">
                <el-popover placement="bottom" width="400" trigger="click">
                  <div>
                    <span style="color:red">可立即补卡(不推荐使用)</span>是若设备离线或通讯设备异常造成消费数据滞后立即补卡会影响补卡的金额比旧卡真实金额多，造成金钱损失
                  </div>
                  <div>
                    <span style="color:red">不可立即补卡</span>是挂失后必须等待所有的挂失卡黑名单下发设备成功后，才可以进行补卡，防止因为黑名单未下发到设备问题造成补卡补多的情况
                  </div>
                  <div slot="reference">
                    <!-- <el-button type="text">提示</el-button> -->
                    <el-button size="medium" class="tishi">提示</el-button>
                  </div>
                </el-popover>
              </el-col>
            </el-form-item>
            <el-form-item label="是否ID发卡模式:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.isIdCardMode"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
              <el-form-item label="是否启用缴费:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.paymentUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="手机端可挂失卡:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.cardLossEnable"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="开通平台钱包:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.platformBalanceEnable"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="手机端可远程开门:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.remoteOpenDoorEnable"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否启用水控功能 :">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.waterUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="水控余额不足提醒的阈值:" :min="0" prop="cardBalanceWaterThreshold">
              <el-col :span="8">
                <el-input-number
                  :min="0"
                  v-model.number="alldata.cardBalanceWaterThreshold"
                  size="mini"
                  :precision="0"
                ></el-input-number>
              </el-col>
              <el-col :span="2" :style="{paddingLeft:'10px'}">分</el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}">
                <el-checkbox v-model="alldata.aliLifeNotify">是否通过生活号提醒</el-checkbox>
              </el-col>
            </el-form-item>
            <el-form-item label="手机端可远程开水控:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.waterControlEnable"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="远程开水时扣费来源:" prop="nonCardWallet">
              <el-col :span="12">
                <el-select
                  v-model="alldata.nonCardWallet"
                  placeholder="请选择"
                  style="width:100%"
                  size="mini"
                >
                  <el-option
                    v-for="item in walletList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>
            <el-form-item label="水控远程开水后最大占用时间:" prop="waterMaxMinutes">
              <el-col :span="12">
                <el-input-number
                  :min="0"
                  v-model="alldata.waterMaxMinutes"
                  size="mini"
                  width="100%"
                  :precision="0"
                ></el-input-number>
              </el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}" :precision="0">分钟</el-col>
            </el-form-item>
            <el-form-item label="水控费率:" prop="waterPrice">
              <el-col :span="12">
                <el-input-number :min="0" v-model="alldata.waterPrice" size="mini" :precision="0"></el-input-number>
              </el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}">分/升</el-col>
            </el-form-item>
            <el-form-item label="水控脉冲:" :min="0" prop="waterPulse">
              <el-col :span="12">
                <el-input-number v-model="alldata.waterPulse" size="mini" :precision="0"></el-input-number>
              </el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}">个</el-col>
            </el-form-item>
            <el-form-item label="水控设备白名单下发范围:" prop="waterRange">
              <el-col :span="12">
                <el-select
                  v-model="alldata.waterRange"
                  placeholder="请选择"
                  style="width:100%"
                  size="mini"
                >
                  <el-option
                    v-for="item in waterRangeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>

            <el-form-item label="是否开启电控功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.electricUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="电控费率:" prop="electricPrice">
              <el-col :span="12">
                <el-input-number
                  :min="0"
                  v-model="alldata.electricPrice"
                  size="mini"
                  :precision="0"
                ></el-input-number>
              </el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}">分/度</el-col>
            </el-form-item>
            <el-form-item label="是否开启消费机功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.consumeUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="消费余额不足提醒的阈值:" :min="0" prop="waterPulse">
              <el-col :span="8">
                <el-input-number
                  :min="0"
                  v-model.number="alldata.cardBalanceThreshold"
                  size="mini"
                  :precision="0"
                ></el-input-number>
              </el-col>
              <el-col :span="2" :style="{paddingLeft:'10px'}">分</el-col>
              <el-col :span="4" :style="{paddingLeft:'10px'}">
                <el-checkbox v-model="alldata.aliLifeNotify">是否通过生活号提醒</el-checkbox>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启门锁功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.empowerUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启门禁功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.entranceUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启电吹风功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.hairDrierUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启voip话机功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.voipUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启空调功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.airUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启归宿终端功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.destinationTerminalUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启无人售货机功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.vendingMachineUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <!-- <el-form-item label="是否开启直饮水机:">
            <el-col :span="4">
              <el-switch
                v-model="alldata.greenbUse"
                active-text="是"
                inactive-text="否"
                active-value="1"
                inactive-value="0"
              ></el-switch>
            </el-col>
            </el-form-item>-->
            <el-form-item label="是否开启自助发卡机功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.cardIssuingUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <el-form-item label="是否开启本地一卡通功能:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.oneCardSolutionUse"
                  active-text="是"
                  inactive-text="否"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>

            <el-form-item label="是否推送人事信息到本地:">
              <el-col :span="4">
                <el-switch
                  v-model="alldata.departmentPush"
                  active-text="是"
                  inactive-text="否"
                  :active-value="1"
                  :inactive-value="0"
                ></el-switch>
              </el-col>
            </el-form-item>
            <!-- <el-form-item>
            <el-button type="primary" @click="onSubmit()">保存信息</el-button>
            </el-form-item>-->
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addvisible()">取消</el-button>
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      uunitGuid: '',
      addDialogFormVisible: false,
      labelPosition: 'right',
      alldata: {
        // 钱包模式设置
        walletModel: '',
        //是否ID发卡模式
        isIdCardMode: '',
        // 是否启用缴费
        paymentUse:"",
        // 挂失后补卡方案
        replaceModel: '',
        //是否挂失卡
        cardLossEnable: '',
        //平台钱包
        nonCardWallet: '',
        //主键
        pkConfigId: '',
        //是否开启平台钱包
        platformBalanceEnable: '',
        //是否可以远程开门
        remoteOpenDoorEnable: '',
        //是否启用水控
        waterUse: '',
        //是否可以远程开水
        waterControlEnable: '',
        //水控无卡消费占用最大时间
        waterMaxMinutes: '',
        //水控费率
        waterPrice: '',
        //水控脉冲
        waterPulse: '',
        // 水控余额不足提醒的阈值
        cardBalanceWaterThreshold: '',
        // 余额调整水控设备下发范围
        waterRange: '',
        //余额不足提醒
        cardBalanceThreshold: '',
        //是否通过生活号提醒
        aliLifeNotify: false,
        // 是否开启电控
        electricUse: 0,
        // 电控费率
        electricPrice: '',
        // 消费机
        consumeUse: 0,
        // 门锁
        empowerUse: 0,
        // 门禁
        entranceUse: 0,
        // 电吹风
        hairDrierUse: 0,
        // viop
        voipUse: 0,
        // 空调
        airUse: 0,
        // 终端
        destinationTerminalUse: 0,
        // 无人售货机
        vendingMachineUse: 0,
        // 饮水机
        greenbUse: 0,
        // 发卡机
        cardIssuingUse: 0,
        // 本地一卡通
        oneCardSolutionUse: 0,
        departmentPush:0
      },
      userGuid: '',
      alldatarule: {
        nonCardWallet: [
          { required: true, message: '平台钱包数据不能为空', trigger: 'blur' }
        ],
        waterMaxMinutes: [
          { required: true, message: '水控无卡消费不能为空', trigger: 'blur' }
        ],
        waterPrice: [
          { required: true, message: '水控费率不能为空', trigger: 'blur' }
        ],
        waterPulse: [
          { required: true, message: '水控脉冲不能为空', trigger: 'blur' }
        ],
        electricPrice: [
          { required: true, message: '电控费率不能为空', trigger: 'blur' }
        ]
      },
      walletList: [
        { label: '平台钱包', value: 100 },
        { label: '卡余额', value: 1 }
      ],
      waterRangeList: [
        { label: '全部 ', value: 1 },
        { label: '楼栋', value: 2 },
        { label: '楼层', value: 3 },
        { label: '房间', value: 4 }
      ],
      walletModelList: [
        { label: '单钱包模式 ', value: 1 },
        { label: '多钱包模式', value: 2 }
      ]
    }
  },
  // props: ["unitGuid"],
  created() {
    this.userGuid = sessionStorage.getItem('administrator')
  },
  mounted() {},
  computed: {
    changeschoolid: {
      get() {
        return this.$store.state.user.changeschoolid
      }
    }
  },
  watch: {},
  methods: {
    handleClick() {
      this.addDialogFormVisible = true
    },
    closeDialog(done) {
      done()
    },
    addvisible() {
      // this.getunitconfiguration();
      this.addDialogFormVisible = false
    },
    unitinit(row) {
      this.unitGuid = row.unitGuid
      this.getunitconfiguration()
      this.addDialogFormVisible = true
    },
    proving1(e) {
      // console.log(e)
    },
    //单位配置信息
    getunitconfiguration() {
      this.$http({
        url: this.$http.adornUrl('/manager/unit-config'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            unitGuid: this.unitGuid,
            userGuid: this.userGuid
          },
          messageType: this.messageType
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.alldata = { ...data.messageContent }
          //是否ID发卡模式
          this.alldata.isIdCardMode = String(data.messageContent.isIdCardMode)

            // 是否启用缴费
             this.alldata.paymentUse = String(data.messageContent.paymentUse)
          //平台钱包
          this.alldata.cardLossEnable = String(
            data.messageContent.cardLossEnable
          )
          //平台钱包
          this.alldata.nonCardWallet = data.messageContent.nonCardWallet
          this.alldata.pkConfigId = data.messageContent.pkConfigId
          this.alldata.platformBalanceEnable = String(
            data.messageContent.platformBalanceEnable
          )
          this.alldata.remoteOpenDoorEnable = String(
            data.messageContent.remoteOpenDoorEnable
          )
          this.alldata.unitGuid = data.messageContent.unitGuid
          this.alldata.waterUse = String(data.messageContent.waterUse)
          this.alldata.waterControlEnable = String(
            data.messageContent.waterControlEnable
          )
          this.alldata.waterMaxMinutes = data.messageContent.waterMaxMinutes
          //水控费率
          this.alldata.waterPrice = data.messageContent.waterPrice
          this.alldata.waterPulse = data.messageContent.waterPulse
          this.alldata.cardBalanceThreshold =
            data.messageContent.cardBalanceThreshold
          this.alldata.aliLifeNotify = data.messageContent.aliLifeNotify
          // 电控费率
          this.alldata.electricPrice = data.messageContent.electricPrice
          // 是否开启电控
          this.alldata.electricUse = String(data.messageContent.electricUse)
          // 消费机
          this.alldata.consumeUse = String(data.messageContent.consumeUse)
          // 门锁
          this.alldata.empowerUse = String(data.messageContent.empowerUse)
          // 门禁
          this.alldata.entranceUse = String(data.messageContent.entranceUse)
          // 电吹风
          this.alldata.hairDrierUse = String(data.messageContent.hairDrierUse)
          // viop
          this.alldata.voipUse = String(data.messageContent.voipUse)
          // 空调
          this.alldata.airUse = String(data.messageContent.airUse)
          // 终端
          this.alldata.destinationTerminalUse = String(
            data.messageContent.destinationTerminalUse
          )
          // 无人售货机
          this.alldata.vendingMachineUse = String(
            data.messageContent.vendingMachineUse
          )
          // 饮水机
          this.alldata.greenbUse = String(data.messageContent.greenbUse)
          // 发卡机
          this.alldata.cardIssuingUse = String(
            data.messageContent.cardIssuingUse
          )
          // 本地一卡通
          this.alldata.oneCardSolutionUse = String(
            data.messageContent.oneCardSolutionUse
          )
          // 余额调整水控设备下发范围
          this.alldata.waterRange = data.messageContent.waterRange
          console.log(this.alldata)
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    onSubmit() {
      this.$refs['alldata'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/manager/update-unit-config'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                ...this.alldata,
                isIdCardMode: parseInt(this.alldata.isIdCardMode),
                paymentUse: parseInt(this.alldata.paymentUse),
                cardLossEnable: parseInt(this.alldata.cardLossEnable),
                nonCardWallet: parseInt(this.alldata.nonCardWallet),
                pkConfigId: this.alldata.pkConfigId,
                platformBalanceEnable: parseInt(
                  this.alldata.platformBalanceEnable
                ),
                remoteOpenDoorEnable: parseInt(
                  this.alldata.remoteOpenDoorEnable
                ),
                unitGuid: this.alldata.unitGuid,
                waterControlEnable: parseInt(this.alldata.waterControlEnable),
                waterUse: parseInt(this.alldata.waterUse),
                waterMaxMinutes: this.alldata.waterMaxMinutes,
                waterPrice: this.alldata.waterPrice,
                waterPulse: this.alldata.waterPulse,
                userGuid: this.userGuid,
                cardBalanceThreshold: this.alldata.cardBalanceThreshold,
                aliLifeNotify: this.alldata.aliLifeNotify,
                // 电控费率
                electricPrice: this.alldata.electricPrice,
                // 是否开启电控
                electricUse: parseInt(this.alldata.electricUse),
                // 消费机
                consumeUse: parseInt(this.alldata.consumeUse),
                // 门锁
                empowerUse: parseInt(this.alldata.empowerUse),
                // 门禁
                entranceUse: parseInt(this.alldata.entranceUse),
                // 电吹风
                hairDrierUse: parseInt(this.alldata.hairDrierUse),
                // viop
                voipUse: parseInt(this.alldata.voipUse),
                // 空调
                airUse: parseInt(this.alldata.airUse),
                // 终端
                destinationTerminalUse: parseInt(
                  this.alldata.destinationTerminalUse
                ),
                // 无人售货机
                vendingMachineUse: parseInt(this.alldata.vendingMachineUse),
                // 饮水机
                greenbUse: parseInt(this.alldata.greenbUse),
                // 发卡机
                cardIssuingUse: parseInt(this.alldata.cardIssuingUse),
                // 本地一卡通
                oneCardSolutionUse: parseInt(this.alldata.oneCardSolutionUse),
                // 余额调整水控设备下发范围
                waterRange: this.alldata.waterRange
              },
              messageType: this.messageType
            })
          }).then(({ data }) => {
            console.log(data)
            if (data.messageCode == 200) {
              this.$message({
                showClose: true,
                message: '配置成功',
                type: 'success'
              })
              this.addDialogFormVisible = false
              // this.getunitconfiguration();
            } else {
              this.$message({
                showClose: true,
                message: data.errorMessage,
                type: 'error'
              })
            }
          })
        }
      })
    },
    cancle() {}
  }
}
</script>

<style lang="scss" scoped>
.setparameter {
  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }
}
.tishi {
  color: #e20600;
  // margin-left: 10px;
  font-size: 12px;
  border: 1px solid #e20600;
  padding: 3px 10px;
  margin-left: 10px;
  font-weight: 800;
}
.unit_parameter {
  margin-left: -100px;
  height: 50vh;
  overflow-y: auto;
  .el-input-number--mini {
    width: 100%;
  }
  padding: 20px;
  padding-top: 0px;
  .header_title {
    padding-left: 22px;
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #e5e9f2;
    color: #909399;
  }
  .list {
    font-size: 16px;
    font-weight: bold;
    color: #909399;
    // padding-top: 20px;
    .el-form-item {
      padding-left: 22px;
      margin-bottom: 0px;
      // padding-top: 18px;
      // border-bottom: 1px solid #e5e9f2;
      width: 100%;
    }
    .el-form-item:last-child {
      border-bottom: 0px solid #e5e9f2;
      // margin-top: 30px;
      // display: flex;
      // justify-content: center;
    }
  }
}
</style>